import React, { Component } from 'react'
import SimpleLayout from './SimpleLayout'
import NormalLayout from './NormalLayout'


class BasicLayout extends Component {

  constructor(props) {
    super(props)
    this.state = {
      baseCompoent: [
        {
          component: props => <SimpleLayout {...props}>{props.children}</SimpleLayout>,
          routes: ['/user']
        },
        {
          component: props => <NormalLayout {...props}>{props.children}</NormalLayout>,
          routes: ['/']
        },
      ]
    }
  }

  pathnameFilter = (param) => {
    const { baseCompoent } = this.state
    const path = baseCompoent.find(item => {
      return item.routes.find(route => {
        const reg = new RegExp(`^${route}+`)
        if (reg.test(param)) {
          return route
        } else {
          return false
        }
      })
    })
    const { component } = path
    return component
  }

  render() {
    const { location: { pathname } } = this.props
    return this.pathnameFilter(pathname)(this.props)
  }
}

export default BasicLayout;
